<?php
/* 	These code was generated using phpCIGen v 2.a (21/05/2012)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com,
	#CV. Trust Solution, jl. Saronojiwo 2/19 Surabaya, http://www.ts.co.id

	+ Module  		: t_rapk View
	+ Description	: For record view
	+ Filename 		: v_t_rapk.php
 	+ creator  		: 
 	+ Created on 24/Jul/2012 10:52:52

*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<style type="text/css">
        p { width:650px; }
		.search-item {
			font:normal 11px tahoma, arial, helvetica, sans-serif;
			padding:3px 10px 3px 10px;
			border:1px solid #fff;
			border-bottom:1px solid #eeeeee;
			white-space:normal;
			color:#555;
		}
		.search-item h3 {
			display:block;
			font:inherit;
			font-weight:bold;
			color:#222;
		}

		.search-item h3 span {
			float: right;
			font-weight:normal;
			margin:0 0 5px 5px;
			width:100px;
			display:block;
			clear:none;
		}
    </style>
<script>
/* declare function */
var t_add_DataStore;
var t_add_ColumnModel;
var t_add_ListEditorGrid;
var t_add_saveForm;
var t_add_SelectedRow;
/* decalare KONSTANSTA */
var FAILED_SAVE="Data gagal disimpan";
var FAILED_CONNECTION="Koneksi database server gagal, hubungi Administrator";
var FAILED_VALID_FORM="Data input belum sempurna";
var FAILED_DELETE_SELECTED="Tidak ada data yang terpilih untuk dihapus";
var FAILED_UPDATE_SELECTED="Tidak ada data yang terpilih untuk diupdate";
var FAILED_DELETE="Data gagal dihapus";
var FAILED_EXCEL="Data gagal diexport ke Excel";
var FAILED_PRINT="Data gagal dicetak";
var FAILED_PERMISSION="Anda tidak mempunyai akses untuk aksi ini";
var CONFIRM_DELETE="Apakah Anda yakin menghapus rekod ini?";
var CONFIRM_MULTI_DELETE="Apakah Anda yakin menghapus rekod-rekod ini?";
var SUCCESS_SAVE="Data sukses disimpan";
var TITLE_LIST="Daftar Data";
var TITLE_FORM="Form Input/Update";
var TITLE_FORM_SEARCH="Pencarian Lanjut";
var BTN_SAVE="Simpan";
var BTN_SEARCH="Cari";
var BTN_CANCEL="Batal";
var BTN_ADD_TITLE="Tambah";
var BTN_EDIT_TITLE="Ubah";
var BTN_DELETE_TITLE="Hapus";
var BTN_SEARCH_TITLE="Pencarian";
var BTN_PRINT_TITLE="Cetak";
var BTN_EXCEL_TITLE="Export Excel";
var BTN_REFRESH_TITLE="Refresh";
var BTN_ADD_TOOLTIP="Tambah Data Baru";
var BTN_EDIT_TOOLTIP="Ubah Data";
var BTN_DELETE_TOOLTIP="Hapus Data";
var BTN_SEARCH_TOOLTIP="Pencarian Data Lanjut";
var BTN_SIMPLE_SEARCH_TOOLTIP="Pencarian Sederhana";
var BTN_PRINT_TOOLTIP="Cetak Data (html)";
var BTN_EXCEL_TOOLTIP="Export ke bentuk Excel";
var BTN_REFERSH_TOOLTIP="Refresh Data";
var INFO_REQUIRED="Wajib diisi";
var PERMISSION="RCUD";
//declare konstant
var post2db = 'CREATE';
var msg = 'created';
var pageS=15;

Ext.ns('App');

/**
 * App.InitialData
 * @extends Ext.Panel
 * This is a specialized Panel which is used to show information about
 * a book.
 *
 * This demonstrates adding 2 custom properties (tplMarkup and
 * startingMarkup) to the class. It also overrides the initComponent
 * method and adds a new method called updateDetail.
 *
 * The class will be registered with an xtype of 'InitialData'
 */
App.InitialData = Ext.extend(Ext.Panel, {
	// add tplMarkup as a new property
	tplMarkup: [
				'<table border="0">',
				'<tr>',
				'<td width="120"><b>No. Kontrak</b></td><td width="10">:</td><td>{kontrak_no}</td>',
				'</tr>',
				'<tr>',
				'<td width="120"><b>Tgl Kontrak</b></td><td width="10">:</td><td>{kontrak_date:date("l")}, {kontrak_date:date("F d")}, {kontrak_date:date("Y")}</td>',
				'</tr>',
				'<tr>',
				'<td width="120"><b>Waktu Pelaksanaan</b></td><td width="10">:</td><td>{kontrak_begin:date("l")}, {kontrak_begin:date("F d")}, {kontrak_begin:date("Y")} <b>s/d</b> {kontrak_end:date("l")}, {kontrak_end:date("F d")}, {kontrak_end:date("Y")}</td>',
				'</tr>',
				'<tr>',
				'<td width="120"><b>Jangka Waktu</b></td><td width="10">:</td><td>{kontrak_jangkawaktu} Hari</td>',
				'</tr>',
				//'<tr>',
				//'<td width="100"><b>Nilai Kontrak</b></td><td width="10">:</td><td>{ba_vendor1}</td>',
				//'</tr>',
				'</table>'
	],
	// startingMarup as a new property
	startingMarkup: 'Informasi detail Data Awal',
	// override initComponent to create and compile the template
	// apply styles to the body of the panel and initialize
	// html to startingMarkup
	initComponent: function() {
		this.tpl = new Ext.Template(this.tplMarkup);
		Ext.apply(this, {
			bodyStyle: {
				background: '#ffffff',
				padding: '7px'
			},
			html: this.startingMarkup
		});
		// call the superclass's initComponent implementation
		App.InitialData.superclass.initComponent.call(this);
	},
	// add a method which updates the details
	updateDetail: function(data) {
		this.tpl.overwrite(this.body, data);
	},
	resetDetail: function(){
		this.tpl = new Ext.Template(this.startingMarkup);
		this.tpl.overwrite(this.body);
	}
});
// register the App.InitialData class with an xtype of InitialData
Ext.reg('initialdata', App.InitialData);

App.VendorData = Ext.extend(Ext.Panel, {
	// add tplMarkup as a new property
	tplMarkup: [
	        	'<table border="0">',
	        	'<tr>',
	        	'<td width="100"><b>Tanggal P1</b></td><td width="10">:</td><td>{project_p1:date("l")}, {project_p1:date("F d")}, {project_p1:date("Y")}</td>',
	        	'</tr>',
	        	'<tr>',
	        	'<td width="100"><b>Nama Subkont</b></td><td width="10">:</td><td>{vendor_name}</td>',
	        	'</tr>',
	        	'<tr>',
	        	'<td width="100"><b>Pengadaan</b></td><td width="10">:</td><td>{job_name}</td>',
	        	'</tr>',
	        	'<tr>',
	        	'<td width="100"><b>Alamat</b></td><td width="10">:</td><td>{vendor_address}</td>',
	        	'</tr>',
	        	'<tr>',
	        	'<td width="100"><b>Direktur</b></td><td width="10">:</td><td>{ba_vendor1}</td>',
	        	'</tr>',
	        	'</table>'
	],
	// startingMarup as a new property
	startingMarkup: 'Informasi detail Data Awal',
	// override initComponent to create and compile the template
	// apply styles to the body of the panel and initialize
	// html to startingMarkup
	initComponent: function() {
		this.tpl = new Ext.Template(this.tplMarkup);
		Ext.apply(this, {
			bodyStyle: {
				background: '#ffffff',
				padding: '7px'
			},
			html: this.startingMarkup
		});
		// call the superclass's initComponent implementation
		App.VendorData.superclass.initComponent.call(this);
	},
	// add a method which updates the details
	updateDetail: function(data) {
		this.tpl.overwrite(this.body, data);
	},
	resetDetail: function(){
		this.tpl = new Ext.Template(this.startingMarkup);
		this.tpl.overwrite(this.body);
	}
});
// register the App.VendorData class with an xtype of VendorData
Ext.reg('vendordata', App.VendorData);

/* on ready fuction */
Ext.onReady(function(){
  	Ext.QuickTips.init();	/* Initiate quick tips icon */
  	
  	Ext.util.Format.comboRenderer = function(combo){
  	    return function(value){
  	        var record = combo.findRecord(combo.valueField, value);
  	        return record ? record.get(combo.displayField) : combo.valueNotFoundText;
  	    };
  	};
  	
  	/* START DATA */
	t_add_datappn = new Ext.data.Store({
		id: 't_project_datappn',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_ppn',
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'setup_ppn'
		},[
			{name: 'setup_ppn', type: 'int', mapping: 'setup_ppn'}
		]),
		sortInfo:{field: 'setup_ppn', direction: "ASC"}
	});
	t_add_datappn.load({params: {start: 0, limit: pageS}});
  	t_add_DataStore = new Ext.data.Store({
		id: 't_add_DataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_add&m=get_action',
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'add_id'
		},[
			{name: 'add_id', type: 'int', mapping: 'add_id'},
			{name: 'add_type', type: 'string', mapping: 'add_type'},
			{name: 'add_seq', type: 'int', mapping: 'add_seq'},
			{name: 'add_reqdate', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'add_reqdate'},
			{name: 'add_reqno', type: 'string', mapping: 'add_reqno'},
			{name: 'add_accdate', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'add_accdate'},
			{name: 'add_accno', type: 'string', mapping: 'add_accno'},
			{name: 'add_date', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'add_date'},
			{name: 'add_no', type: 'string', mapping: 'add_no'},
			{name: 'add_begin', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'add_begin'},
			{name: 'add_end', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'add_end'},
			{name: 'add_value', type: 'float', mapping: 'add_value'},
			{name: 'kontrak_no', type: 'string', mapping: 'kontrak_no'},
			{name: 'kontrak_begin', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'kontrak_begin'},
			{name: 'kontrak_end', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'kontrak_end'},
			{name: 'branch_id', type: 'int', mapping: 'branch_id'},
			{name: 'branch_name', type: 'string', mapping: 'branch_name'},
			{name: 'project_id', type: 'int', mapping: 'project_id'},
			{name: 'project_name', type: 'string', mapping: 'project_name'},
			{name: 'project_code', type: 'string', mapping: 'project_code'},
			{name: 'job_id', type: 'int', mapping: 'job_id'},
			{name: 'job_name', type: 'string', mapping: 'job_name'},
			{name: 'vendor_id', type: 'int', mapping: 'vendor_id'},
			{name: 'vendor_name', type: 'string', mapping: 'vendor_name'}
		]),
		sortInfo:{field: 'project_code', direction: "ASC"}
	});
  	t_add_DataStore.load({params: {start: 0, limit: pageS}});	// load DataStore
  	
  	var branchDataStore = new Ext.data.Store({
		id: 'branchDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_branch', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'branch_id'
		},[
			{name: 'branch_id', type: 'int', mapping: 'branch_id'},
			{name: 'branch_name', type: 'string', mapping: 'branch_name'},
			{name: 'branch_active', type: 'string', mapping: 'branch_active'},
			{name: 'dvo_id', type: 'int', mapping: 'dvo_id'},
			{name: 'dvo_name', type: 'string', mapping: 'dvo_name'}
		]),
		sortInfo:{field: 'branch_name', direction: "ASC"}
	});
	
	var projectDataStore = new Ext.data.Store({
		id: 'projectDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_project', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'project_id'
		},[
			{name: 'project_id', type: 'int', mapping: 'project_id'},
			{name: 'project_name', type: 'string', mapping: 'project_name'},
			{name: 'project_code', type: 'string', mapping: 'project_code'}
		]),
		sortInfo:{field: 'project_code', direction: "ASC"}
	});
	var tpl_projectDS = new Ext.XTemplate(
			'<tpl for="."><div class="search-item">',
            '<span><b>[{project_code}]</b><br /></span>',
            '{project_name}',
            '</div></tpl>'
	);

	var kontrakDataStore = new Ext.data.Store({
		id: 'kontrakDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_kontrak', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'kontrak_id'
		},[
			{name: 'kontrak_id', type: 'int', mapping: 'kontrak_id'},
			{name: 'kontrak_no', type: 'string', mapping: 'kontrak_no'},
			{name: 'kontrak_date', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'kontrak_date'},
			{name: 'kontrak_begin', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'kontrak_begin'},
			{name: 'kontrak_end', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'kontrak_end'},
			{name: 'kontrak_jangkawaktu', type: 'int', mapping: 'kontrak_jangkawaktu'},
			{name: 'project_name', type: 'string', mapping: 'project_name'},
			{name: 'project_code', type: 'string', mapping: 'project_code'},
			{name: 'project_p1', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'project_p1'},
			{name: 'vendor_id', type: 'string', mapping: 'vendor_id'},
			{name: 'vendor_name', type: 'string', mapping: 'vendor_name'},
			{name: 'vendor_address', type: 'string', mapping: 'vendor_address'},
			{name: 'job_id', type: 'string', mapping: 'job_id'},
			{name: 'job_name', type: 'string', mapping: 'job_name'},
			{name: 'ba_vendor1', type: 'string', mapping: 'ba_vendor1'}
		]),
		sortInfo:{field: 'project_code', direction: "ASC"}
	});
	var tpl_kontrakDS = new Ext.XTemplate(
		'<tpl for="."><div class="search-item">',
        '<span><b>[{kontrak_no}]</b><br /></span>',
        'Kode Proyek: {project_code}',
        'Nama Proyek: {project_name}',
        '</div></tpl>'
	);

	var jobdetDataStore = new Ext.data.Store({
		id: 'jobdetDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_add&m=get_jobdet_all', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'jobdet_id'
		},[
			{name: 'jobdet_id', type: 'int', mapping: 'jobdet_id'},
			{name: 'jobdet_name', type: 'string', mapping: 'jobdet_name'},
			{name: 'badet_id', type: 'int', mapping: 'badet_id'}
		]),
		sortInfo:{field: 'jobdet_name', direction: "ASC"}
	});
	var tpl_jobdetDS = new Ext.XTemplate(
			'<tpl for="."><div class="search-item">',
            '<span><b>[{jobdet_name}]</b><br /></span>',
            'Material: {job_name}',
            '</div></tpl>'
	);
	
	var unitDataStore = new Ext.data.Store({
		id: 'unitDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_unit', 
			method: 'POST'
		}),
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'unit_id'
		},[
			{name: 'unit_id', type: 'int', mapping: 'unit_id'},
			{name: 'unit_name', type: 'string', mapping: 'unit_name'}
		]),
		sortInfo:{field: 'unit_name', direction: "ASC"}
	});

	var adddet_reader=new Ext.data.JsonReader({
		root: 'results',
		totalProperty: 'total'
	//	id: 'jobdet_id'
	},[
	/* dataIndex => insert intoperawatan_ColumnModel, Mapping => for initiate table column */
			{name: 'adddet_id', type: 'int', mapping: 'adddet_id'},
			{name: 'badet_id', type: 'int', mapping: 'badet_id'}, 
			{name: 'jobdet_id', type: 'int', mapping: 'jobdet_id'}, 
			{name: 'jobdet_name', type: 'string', mapping: 'jobdet_name'},
			{name: 'volume', type: 'float', mapping: 'volume'},
			{name: 'volume_add', type: 'float', mapping: 'volume_add'},
			{name: 'unit_id', type: 'int', mapping: 'unit_id'},
			{name: 'unit_name', type: 'string', mapping: 'unit_name'},
			{name: 'kompdet_price', type: 'float', mapping: 'kompdet_price'},
			{name: 'adddet_price', type: 'float', mapping: 'adddet_price'},
			{name: 'status', type: 'string', mapping: 'status'},
			{name: 'kompdet_lft', type: 'int', mapping: 'kompdet_lft'}
	]);
	
	var adddetDataStore = new Ext.data.Store({
		id: 'adddetDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_add&m=adddet_list', 
			method: 'POST'
		}),
		reader: adddet_reader
	});
  	/* END DATA */
  	
  	
  	/* START FORM */
	//Form Create/Update
	var add_idField = new Ext.form.NumberField({
		id: 'add_idField',
		fieldLabel: 'Project Id ',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		hidden: true,
		maskRe: /([0-9]+)$/
	});
	var add_branchField = new Ext.form.ComboBox({
		id: 'add_branchField',
		fieldLabel: 'Cabang <font color=red>*</font>',
		store: branchDataStore,
		mode: 'remote',
		displayField:'branch_name',
		valueField: 'branch_id',
        editable: false,
        forceSelection: true,
        anchor: '95%',
		pageSize: 15,
		triggerAction: 'all'
	});
	add_branchField.on('select', function(){
		projectDataStore.setBaseParam('branch_id', add_branchField.getValue());
		projectDataStore.load();
		add_branchField.disable();
	});
	var add_projectField = new Ext.form.ComboBox({
		id: 'add_projectField',
		fieldLabel: 'Kode Proyek',
		store: projectDataStore,
		mode: 'local',
		displayField:'project_code',
		valueField: 'project_id',
        editable: true,
        anchor: '95%',
		pageSize: 15,
		itemSelector: 'div.search-item',
		tpl: tpl_projectDS,
		triggerAction: 'all'
	});
	add_projectField.on('select', function(){
		var record = add_projectField.findRecord(add_projectField.valueField, add_projectField.getValue());
		//add_projectNameField.setValue(record.get(add_projectField.displayField));
		add_projectNameField.setValue(record.data.project_name);

		kontrakDataStore.setBaseParam('branch_id', add_branchField.getValue());
		kontrakDataStore.setBaseParam('project_id', add_projectField.getValue());
		kontrakDataStore.load();
		add_projectField.disable();
	});
	var add_projectNameField = new Ext.form.TextField({
		id: 'add_projectNameField',
		fieldLabel: 'Nama Proyek',
		anchor: '95%',
		readOnly: true
	});
	var add_kontrakField = new Ext.form.ComboBox({
		id: 'add_kontrakField',
		fieldLabel: 'No. Kontrak',
		store: kontrakDataStore,
		mode: 'local',
		displayField:'kontrak_no',
		valueField: 'kontrak_id',
        editable: true,
        anchor: '95%',
		pageSize: 15,
		itemSelector: 'div.search-item',
		tpl: tpl_kontrakDS,
		triggerAction: 'all'
	});
	var kontrakselect = function(){
		var record = add_kontrakField.findRecord(add_kontrakField.valueField, add_kontrakField.getValue());
		add_vendorDataField.updateDetail(record.data);
		add_initialDataField.updateDetail(record.data);
		
		add_pelaksanaan_datestartField.setValue(record.data.kontrak_begin);
		add_kontrakend_dateField.setValue(record.data.kontrak_end);

		var addbegindate = new Date();
		addbegindate.setTime(record.data.kontrak_end.getTime() + (1 * 24 * 3600 * 1000));
		add_begin_dateField.setValue(addbegindate.format('Y-m-d'));

		jobdetDataStore.load({
			callback: function(opts, success, response){
				unitDataStore.load({
					callback: function(opts, success, response){
						adddetDataStore.setBaseParam('kontrak_no', record.data.kontrak_no);
						adddetDataStore.setBaseParam('add_id', '0');
						adddetDataStore.load({
							callback: function(opts, success, response){
								var jmlawal = 0;
								var jmladd = 0;
								for(var i=0; i<adddetDataStore.getCount(); i++){
									jmlawal += (adddetDataStore.getAt(i).data.volume * adddetDataStore.getAt(i).data.kompdet_price);
									jmladd += (adddetDataStore.getAt(i).data.volume_add * adddetDataStore.getAt(i).data.adddet_price);
								}
								add_jmlawal_cfField.setValue(formatCurrency(jmlawal));
								set_valueminppn(jmlawal, 'nkawal');
								add_jmladd_cfField.setValue(formatCurrency(jmladd));
								set_valueminppn(jmladd, 'nkadd');
							}
						});
					}
				});
				
			}
		});
		
	};
	add_kontrakField.on('select', kontrakselect);
	var add_typeField = new Ext.form.ComboBox({
		id: 'add_typeField',
		fieldLabel: 'Jenis Addendum',
		forceSelection: true,
		store:new Ext.data.SimpleStore({
			fields:['valueText', 'displayText'],
			data:[['Waktu','Waktu'],['NK','NK'],['NK dan Waktu', 'NK dan Waktu']]
		}),
		mode: 'local',
		displayField: 'displayText',
		valueField: 'valueText',
		width: 120,
		allowBlank: false,
		triggerAction: 'all',
		listeners : {
			'select' : function(a,b,c){
				if (c == 1){
					add_jangkawaktuField.reset();
					add_jangkawaktuField.setVisible(false);
					add_begin_dateField.setVisible(false);
					add_kontrakend_dateField.setVisible(false);
					add_pelaksanaan_datestartField.setVisible(false);
					add_pelaksanaan_dateendField.setVisible(false);
				}else{
					add_jangkawaktuField.setVisible(true);
					add_begin_dateField.setVisible(true);
					add_kontrakend_dateField.setVisible(true);
					add_pelaksanaan_datestartField.setVisible(true);
					add_pelaksanaan_dateendField.setVisible(true);
				}

				if (c == 0){
					adddet_jobdetField.setReadOnly(true);
					adddet_unitField.setReadOnly(true);
					Ext.getCmp('editor_hargaadd').setReadOnly(true);
					// Ext.getCmp('editor_vol').setReadOnly(true);
				}else{
					adddet_jobdetField.setReadOnly(false);
					adddet_unitField.setReadOnly(false);
					Ext.getCmp('editor_hargaadd').setReadOnly(false);
					// Ext.getCmp('editor_vol').setReadOnly(false);
				}
			}
		}
	});
	var add_seqField = new Ext.form.NumberField({
		id: 'add_seqField',
		fieldLabel: 'Amandemen Ke',
		allowDecimals: true,
		allowNegative: false,
		blankText: '0',
		width: 50,
		maskRe: /([0-9]+)$/
	});
	
	
	var add_vendorDataField = new App.VendorData({
		id: 'add_vendorDataField'
	});

	var add_reqDateField= new Ext.form.DateField({
		id: 'add_reqDateField',
		fieldLabel: 'Tgl Permohonan Add',
		format : 'l, F d, Y',
		//disabledDays: [0, 6],
		anchor: '95%'
	});
	/*add_reqDateField.on('select', function(){
		console.log(add_reqDateField.getValue().format('m'));
		console.log(this.getValue().getTime() + (2 * 24 * 3600 * 1000));
		var newdate = new Date();
		newdate.setTime(this.getValue().getTime() + (2 * 24 * 3600 * 1000));
	    add_accDateField.setValue(newdate.format('Y-m-d'));
	});*/
	var add_reqNoField= new Ext.form.TextField({
		id: 'add_reqNoField',
		fieldLabel: 'No. Surat Permohonan Add',
		anchor: '95%',
		readOnly: false
	});
	var add_accDateField= new Ext.form.DateField({
		id: 'add_accDateField',
		fieldLabel: 'Tgl Persetujuan Add',
		name: 'add_accDateField',
		format : 'l, F d, Y',
		anchor: '95%'
	});
	var add_accNoField= new Ext.form.TextField({
		id: 'add_accNoField',
		fieldLabel: 'No. Surat Persetujuan Add',
		anchor: '95%',
		readOnly: false
	});
	var add_dateField= new Ext.form.DateField({
		id: 'add_dateField',
		fieldLabel: 'Tgl Kontrak Add',
		format : 'l, F d, Y',
		anchor: '95%'
	});
	var add_noField = new Ext.form.TextField({
		id: 'add_noField',
		fieldLabel: 'No. Kontrak Add',
		maxLength: 45,
		allowBlank: false,
		width: 220
	});
	var add_jangkawaktuField = new Ext.form.NumberField({
		id: 'add_jangkawaktuField',
		fieldLabel: 'Penambahan hari',
		allowDecimals: false,
		allowNegative: false,
		blankText: '0',
		width: 50,
		enableKeyEvents: true,
		maskRe: /([0-9]+)$/
	});
	add_jangkawaktuField.on('keyup', function(){
		var newdate = new Date();
		newdate.setTime(add_kontrakend_dateField.getValue().getTime() + (add_jangkawaktuField.getValue() * 24 * 3600 * 1000));
		add_pelaksanaan_dateendField.setValue(newdate.format('Y-m-d'));
	});
	var add_begin_dateField = new Ext.form.DateField({
		id: 'add_begin_dateField',
		fieldLabel: 'Waktu Awal Add',
		format : 'l, F d, Y',
		allowBlank: false,
		readOnly: true,
		width: 200
	});
	var add_kontrakend_dateField = new Ext.form.DateField({
		id: 'add_kontrakend_dateField',
		fieldLabel: 'Akhir Waktu Pelaksanaan',
		format : 'l, F d, Y',
		allowBlank: false,
		readOnly: true,
		width: 200
	});
	var add_pelaksanaan_datestartField = new Ext.form.DateField({
		id: 'add_pelaksanaan_datestartField',
		fieldLabel: 'Waktu Pelaksanaan',
		format : 'l, F d, Y',
		allowBlank: false,
		readOnly: true,
		width: 200
	});
	var add_pelaksanaan_dateendField = new Ext.form.DateField({
		id: 'add_pelaksanaan_dateendField',
		fieldLabel: '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s/d',
		format : 'l, F d, Y',
		allowBlank: false,
		readOnly: true,
		width: 200
	});
	var add_valueField = new Ext.form.NumberField({
		id: 'add_valueField',
		allowDecimals: true,
		allowNegative: false,
		blankText: '0',
		maskRe: /([0-9]+)$/
	});
	var add_value_cfField = new Ext.form.TextField({
		id: 'add_value_cfField',
		fieldLabel: 'Nilai Kontrak (Rp)',
		allowNegatife : false,
		enableKeyEvents: true,
		itemCls: 'rmoney',
		width: 160,
		readOnly: true,
		maskRe: /([0-9]+)$/ 
	});
	var add_dataAddGroup = new Ext.form.FieldSet({
		title: 'Data Addendum',
		labelWidth: 140,
		autoHeight: true,
		collapsible: false,
		layout:'form',
		frame: false,
		items:[add_reqDateField, add_reqNoField, add_accDateField, add_accNoField, add_dateField, add_noField, add_jangkawaktuField,
		       add_pelaksanaan_datestartField, add_pelaksanaan_dateendField/*{
					layout: 'column',
					border: false,
					items:[{
						columnWidth:0.45,
						layout: 'form',
						border:false,
						labelWidth: 130,
						items:[add_pelaksanaan_datestartField]
					},{
						columnWidth:0.55,
						layout: 'form',
						border:false,
						labelWidth: 25,
						items: [add_pelaksanaan_dateendField]
					}]
				}*/,add_value_cfField]
	});

	var add_initialDataField = new App.InitialData({
		id: 'add_initialDataField'
	});
	var add_dataAwalGroup = new Ext.form.FieldSet({
		title: 'Data Awal',
		labelWidth: 140,
		autoHeight: true,
		collapsible: false,
		layout:'form',
		frame: false,
		items:[add_initialDataField]
	});
	
	var add_jmlawal_cfField = new Ext.form.TextField({
		id: 'add_jmlawal_cfField',
		fieldLabel: 'Jumlah Awal (Rp)',
		allowNegatife : false,
		enableKeyEvents: true,
		itemCls: 'rmoney',
		width: 160,
		maskRe: /([0-9]+)$/
	});
	var add_jmlnkawal_cfField = new Ext.form.TextField({
		id: 'add_jmlnkawal_cfField',
		fieldLabel: 'NK Awal (Rp)',
		allowNegatife : false,
		enableKeyEvents: true,
		itemCls: 'rmoney',
		width: 160,
		readOnly: true,
		maskRe: /([0-9]+)$/ 
	});
	var add_jmladd_cfField = new Ext.form.TextField({
		id: 'add_jmladd_cfField',
		fieldLabel: 'Jumlah Add (Rp)',
		allowNegatife : false,
		enableKeyEvents: true,
		itemCls: 'rmoney',
		width: 160,
		readOnly: true,
		maskRe: /([0-9]+)$/ 
	});
	var add_jmlnkadd_cfField = new Ext.form.TextField({
		id: 'add_jmlnkadd_cfField',
		fieldLabel: 'NK Add (Rp)',
		allowNegatife : false,
		enableKeyEvents: true,
		itemCls: 'rmoney',
		width: 160,
		readOnly: true,
		maskRe: /([0-9]+)$/ 
	});
	var add_jmlGroup = new Ext.form.FieldSet({
		title: '',
		labelWidth: 140,
		autoHeight: true,
		collapsible: false,
		layout:'form',
		frame: false,
		items:[{
			layout: 'column',
			border: false,
			items:[{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items:[add_jmlawal_cfField, add_jmlnkawal_cfField ]
			},{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items:[add_jmladd_cfField, add_jmlnkadd_cfField ]
			}]
		}]
	});

	//variable for detail grid
	var adddet_badet_idField = new Ext.form.NumberField({
		id: 'adddet_badet_idField',
		allowDecimals: true,
		allowNegative: false,
		blankText: '0',
		maskRe: /([0-9]+)$/
	});
	var adddet_jobdetField = new Ext.form.ComboBox({
		store: jobdetDataStore,
		mode: 'remote',
		displayField: 'jobdet_name',
		valueField: 'jobdet_id',
		loadingText: 'Searching...',
		typeAhead: false,
		pageSize: pageS,
		triggerAction: 'all',
		lazyRender:false,
		tpl: tpl_jobdetDS,
		itemSelector: 'div.search-item',
		listClass: 'x-combo-list-small',
		anchor: '80%',
		hideTrigger: false,
		forceSelection:true
	});
	adddet_jobdetField.on('select', function(){
		var record = adddet_jobdetField.findRecord(adddet_jobdetField.valueField, adddet_jobdetField.getValue());
		adddet_badet_idField.setValue(record.data.badet_id);
	});
	var adddet_unitField = new Ext.form.ComboBox({
		id: 'adddet_unitField',
		store: unitDataStore,
		mode: 'remote',
		displayField:'unit_name',
		valueField: 'unit_id',
        editable: false,
        forceSelection: true,
		triggerAction: 'all'
	});
	
	var adddet_ColumnModel = new Ext.grid.ColumnModel(
		[{
			header: 'Adddet Id',
			dataIndex: 'adddet_id',
			width: 150,
			sortable: false,
			hidden: true
		},
		{
			header: 'Badet Id',
			dataIndex: 'badet_id',
			width: 150,
			sortable: false,
			hidden: true
		},
		{
			header: 'Uraian',
			id: 'uraian',
			dataIndex: 'jobdet_name',
			editor: new Ext.form.TextField({
				hideLabel: true,
				readOnly : true
			})
		},
		{
			header: 'Jenis, Merk, dan Ukuran Material',
			id: 'jobdet_jenis_merk_ukuran',
			dataIndex: 'jobdet_id',
			editor: adddet_jobdetField,
			sortable: false,
			renderer: Ext.util.Format.comboRenderer(adddet_jobdetField)
		},
		{
			header: 'Vol',
			dataIndex: 'volume',
			width: 90,
			sortable: false,
			align: 'right',
			editor: new Ext.form.NumberField({
				allowDecimals: true,
				id : 'editor_vol',
				allowNegative: false,
				readOnly : true,
				blankText: '0',
				maxLength: 10,
				maskRe: /([0-9]+)$/
			}),
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Sat',
			dataIndex: 'unit_id',
			width: 90,
			sortable: false,
			editor: adddet_unitField,
			renderer: Ext.util.Format.comboRenderer(adddet_unitField)
		},
		{
			header: 'Harga',
			dataIndex: 'kompdet_price',
			width: 90,
			sortable: false,
			align: 'right',
			editor: new Ext.form.NumberField({
				allowDecimals: true,
				id : 'kompdet_price',
				readOnly : true,
				allowNegative: false,
				blankText: '0',
				maxLength: 10,
				maskRe: /([0-9]+)$/
			}),
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Jumlah',
			dataIndex: 'adddet_kompjumlah',
			width: 100,
			sortable: false,
			align: 'right',
			renderer: function(v, params, record){
				return Ext.util.Format.number(record.data.volume * record.data.kompdet_price,'0.000/i');
            }
		},
		{
			header: 'Vol Add',
			dataIndex: 'volume_add',
			width: 90,
			sortable: false,
			align: 'right',
			editor: new Ext.form.NumberField({
				allowDecimals: true,
				id : 'editor_voladd',
				allowNegative: false,
				blankText: '0',
				maxLength: 10,
				maskRe: /([0-9]+)$/
			}),
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Harga Add',
			dataIndex: 'adddet_price',
			width: 90,
			sortable: false,
			align: 'right',
			editor: new Ext.form.NumberField({
				allowDecimals: true,
				id : 'editor_hargaadd',
				allowNegative: false,
				blankText: '0',
				maxLength: 15,
				maskRe: /([0-9]+)$/
			}),
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Jumlah Add',
			dataIndex: 'adddet_jumlah',
			width: 100,
			sortable: false,
			align: 'right',
			renderer: function(v, params, record){
				return Ext.util.Format.number(record.data.volume_add * record.data.adddet_price,'0.000/i');
            }
		},
		{
			header: 'Status',
			dataIndex: 'status',
			sortable: false,
			editor: new Ext.form.TextField({
				readOnly: true
			})
		}]
	);
	adddet_ColumnModel.defaultSortable= true;
	
	var editor_m_jobdet = new Ext.ux.grid.RowEditor({
        saveText: 'Update',
        clicksToEdit:2,
        listeners: {
        	'afteredit': function(){
        		var jmlawal = 0;
				var jmladd = 0;
        		
        		var detail_store = adddetListEditorGrid.getStore();
        		for(var i=0;i<detail_store.getCount();i++){
            		var vol = detail_store.getAt(i).data.volume_add;
            		var hrg = detail_store.getAt(i).data.adddet_price;
            		if(vol !== undefined && hrg !== undefined){
            			jmlawal+= (detail_store.getAt(i).data.volume * detail_store.getAt(i).data.kompdet_price);
            			jmladd+= (detail_store.getAt(i).data.volume_add * detail_store.getAt(i).data.adddet_price);
            		}
        			
        		}
        		add_jmlawal_cfField.setValue(formatCurrency(jmlawal));
				add_jmladd_cfField.setValue(formatCurrency(jmladd));
				add_valueField.setValue(jmladd);
				add_value_cfField.setValue(formatCurrency(jmladd));
				set_valueminppn(jmladd, 'nkadd');
        	}
        }
    });
		
	var adddetListEditorGrid = new Ext.grid.EditorGridPanel({
		id: 'adddetListEditorGrid',
		title: 'Detail Item Addendum',
		height: 250,
		width: 960,
		autoScroll: true,
		store: adddetDataStore, // DataStore
		colModel: adddet_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		region: 'center',
        margins: '0 5 5 5',
		plugins: [editor_m_jobdet],
		frame: true,
		autoExpandColumn: 'jobdet_jenis_merk_ukuran',
		//clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:false},
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: adddetDataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [{
			text: 'Add',
			tooltip: 'Add new detail record',
			iconCls:'icon-adds',    				// this is defined in our styles.css
			handler: adddet_add
		}]
	});
	adddetListEditorGrid.on('afteredit',function(evt){
		var jmlawal = 0;
		var jmladd = 0;
		
		var detail_store = adddetListEditorGrid.getStore();
		for(var i=0;i<detail_store.getCount();i++){
			var vol = detail_store.getAt(i).data.volume_add;
			var hrg = detail_store.getAt(i).data.adddet_price;
			if(vol !== undefined && hrg !== undefined){
				jmlawal+= (detail_store.getAt(i).data.volume * detail_store.getAt(i).data.kompdet_price);
				jmladd+= (detail_store.getAt(i).data.volume_add * detail_store.getAt(i).data.adddet_price);
			}
			
		}
		add_jmlawal_cfField.setValue(formatCurrency(jmlawal));
		add_jmladd_cfField.setValue(formatCurrency(jmladd));
		add_valueField.setValue(jmladd);
		add_value_cfField.setValue(formatCurrency(jmladd));
		set_valueminppn(jmladd, 'nkadd');
	});
	var t_add_btn_Save = new Ext.Button({
		text: BTN_SAVE,
		handler: t_add_save
	});
	t_add_saveForm = new Ext.FormPanel({
		labelAlign: 'left',
		title: TITLE_FORM+' Addendum',
		bodyStyle:'padding:5px',
		autoHeight:true,
		width: 980,
		collapsible: true,
		frame: true,
		renderTo: 'elwindow_t_add_save',
		layout:'form',
		items:[{
			layout: 'column',
			border: false,
			items:[{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items:[add_idField ,add_branchField ,add_projectField ,add_projectNameField ,add_kontrakField ,add_typeField ,add_seqField ]
			},{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items:[add_vendorDataField]
			}]
		},{
			layout: 'column',
			border: false,
			items:[{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items:[add_dataAddGroup ]
			},{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items:[add_dataAwalGroup ]
			}]
		}, adddetListEditorGrid, add_jmlGroup ],
		buttons: [t_add_btn_Save
			,{
				text: BTN_CANCEL,
				handler: function(){
					t_add_reset_form();
				}
			}
		]
	});

	t_add_ColumnModel = new Ext.grid.ColumnModel(
		[{
			header: 'Add Id',
			dataIndex: 'add_id',
			width: 150,
			sortable: false,
			hidden: true
		},
		{
			header: 'No. Kontrak',
			dataIndex: 'kontrak_no',
			width: 150,
			sortable: false
		},
		{
			header: 'Cabang',
			dataIndex: 'branch_name',
			width: 150,
			sortable: false
		},
		{
			header: 'Kode Proyek',
			dataIndex: 'project_code',
			width: 150,
			sortable: false
		},
		{
			header: 'Nama Proyek',
			dataIndex: 'project_name',
			width: 150,
			sortable: false
		},
		{
			header: 'Jenis Pekerjaan',
			dataIndex: 'job_name',
			width: 150,
			sortable: false
		},{
			header: 'Vendor',
			dataIndex: 'vendor_name',
			width: 150,
			sortable: false
		}	]);

	t_add_ColumnModel.defaultSortable= true;
	/* Button Control */
    t_add_gbtn_add=new Ext.Button({
	    text: BTN_ADD_TITLE,
		tooltip: BTN_ADD_TOOLTIP,
		iconCls:'icon-adds',
		handler: display_form_window
    });

    t_add_gbtn_update=new Ext.Button({
	    text: BTN_EDIT_TITLE,
		tooltip: BTN_EDIT_TOOLTIP,
		iconCls:'icon-update',
		handler: t_add_confirm_update
	});

    t_add_gbtn_delete=new Ext.Button({
	    text: BTN_DELETE_TITLE,
		tooltip: BTN_DELETE_TOOLTIP,
		iconCls:'icon-delete',
		handler: t_add_confirm_delete
	});
	t_add_ListEditorGrid =  new Ext.grid.EditorGridPanel({
		id: 't_add_ListEditorGrid',
		el: 'fp_t_add',
		title: TITLE_LIST,
		autoHeight: true,
		collapsible: true,
		store: t_add_DataStore, // DataStore
		cm: t_add_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		frame: true,
		clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:true },
	  	width: 1024,
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: t_add_DataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [
		t_add_gbtn_add, '-',
		t_add_gbtn_update, '-',
		t_add_gbtn_delete, '-',
		new Ext.app.SearchField({
			store: t_add_DataStore,
			listeners:{
				specialkey: function(f,e){
					if(e.getKey() == e.ENTER){
						t_add_DataStore.baseParams={task:'LIST', start:0, limit:pageS};
		            }
				},
				render: function(c){
				Ext.get(this.id).set({qtitle: BTN_SIMPLE_SEARCH_TOOLTIP});
				}
			},
			width: 120
		}),'-',{
			text: BTN_REFRESH_TITLE,
			tooltip: BTN_REFERSH_TOOLTIP,
			handler: t_add_refresh,
			iconCls:'icon-refresh'
		} ]
	});
	t_add_ListEditorGrid.render();
  	/* END FORM */
  	
  	/* START FUNCTION */
	function set_valueminppn(value, field){
		var ppn_datarecord = t_add_datappn.getAt(0).data;
		var ppn = ppn_datarecord.setup_ppn;
		var ppn_nilai = value * ppn / 100;
		var valueminppn = value + ppn_nilai;
		if(field == "nkawal"){
			add_jmlnkawal_cfField.setValue(formatCurrency(Math.ceil(valueminppn)));
		}else{
			add_jmlnkadd_cfField.setValue(formatCurrency(Math.ceil(valueminppn)));
		}
	}
  	function DateFmt() {
	  	this.dateMarkers = {
	     	d:['getDate',function(v) { return ("0"+v).substr(-2,2)}], 
	         	m:['getMonth',function(v) { return ("0"+v).substr(-2,2)}],
	         	n:['getMonth',function(v) {
	             	var mthNames = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
	             	return mthNames[v];
	       		}],
	        	w:['getDay',function(v) {
	             	var dayNames = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
	             	return dayNames[v];
	            }],
	         	y:['getFullYear'],
	         	H:['getHours',function(v) { return ("0"+v).substr(-2,2)}],
	         	M:['getMinutes',function(v) { return ("0"+v).substr(-2,2)}],
	         	S:['getSeconds',function(v) { return ("0"+v).substr(-2,2)}],
	         	i:['toISOString',null]
	  	};
	
	  	this.format = function(date, fmt) {
	    	var dateMarkers = this.dateMarkers
	    	var dateTxt = fmt.replace(/%(.)/g, function(m, p){
	    		var rv = date[(dateMarkers[p])[0]]()
				
	    		if ( dateMarkers[p][1] != null ) rv = dateMarkers[p][1](rv)
	
	    		return rv
	  		});
	
	  		return dateTxt
	  	}
	}
	
	/*var fmt = new DateFmt();
	var date_now = new Date('2012/10/22,12:46:10');
	v = fmt.format(new Date('2012/10/22,12:46:10'),"%w %d:%n:%y - %H:%M:%S");
	console.log(date_now);*/

  	function adddet_add(){
	  	var lastrecord = adddetListEditorGrid.getStore().getCount();
		var edit_adddet= new adddetListEditorGrid.store.recordType({
			adddet_id: 0,
			badet_id: 0,
			jobdet_id: 0,
			volume: 0,
			unit: '',
			adddet_price: 0,
			status: 'addendum'
		});
		editor_m_jobdet.stopEditing();
		adddetDataStore.insert(lastrecord, edit_adddet);
		//adddetListEditorGrid.getView().refresh();
		adddetListEditorGrid.getSelectionModel().selectRow(lastrecord);
		editor_m_jobdet.startEditing(lastrecord);
	}

  	function t_add_save(){

		var patt=new RegExp("U");
		var patt2=new RegExp("C");
		if(patt.test(PERMISSION)==false && patt2.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{
			if(is_t_add_form_valid()){
				var add_id_field=null;
				var add_kontrak_field=null;
				var add_type_field=null;
				var add_seq_field=null;
				var add_req_date_field=null;
				var add_req_no_field=null;
				var add_acc_date_field=null;
				var add_acc_no_field=null;
				var add_date_field=null;
				var add_no_field=null;
				var add_begin_date_field=null;
				var add_end_date_field=null;
				var add_value_field=null;
	
				if((add_idField.getValue() !== null) && (add_idField.getValue() !== "")){add_id_field = add_idField.getValue();}
				//if((add_projectField.getValue() !== null) && (add_projectField.getValue() !== "")){add_kontrak_field = add_projectField.getValue();}
				if((add_kontrakField.getValue() !== null) && (add_kontrakField.getValue() !== "")){add_kontrak_field = add_kontrakField.getValue();}
				if((add_typeField.getValue() !== null) && (add_typeField.getValue() !== "")){add_type_field = add_typeField.getValue();}
				if((add_seqField.getValue() !== null) && (add_seqField.getValue() !== "")){add_seq_field = add_seqField.getValue();}
				if((add_reqDateField.getValue() !== null) && (add_reqDateField.getValue() !== "")){add_req_date_field = add_reqDateField.getValue();}
				if((add_reqNoField.getValue() !== null) && (add_reqNoField.getValue() !== "")){add_req_no_field = add_reqNoField.getValue();}
				if((add_accDateField.getValue() !== null) && (add_accDateField.getValue() !== "")){add_acc_date_field = add_accDateField.getValue();}
				if((add_accNoField.getValue() !== null) && (add_accNoField.getValue() !== "")){add_acc_no_field = add_accNoField.getValue();}
				if((add_dateField.getValue() !== null) && (add_dateField.getValue() !== "")){add_date_field = add_dateField.getValue();}
				if((add_noField.getValue() !== null) && (add_noField.getValue() !== "")){add_no_field = add_noField.getValue();}
				if((add_begin_dateField.getValue() !== null) && (add_begin_dateField.getValue() !== "")){add_begin_date_field = add_begin_dateField.getValue();}
				if((add_pelaksanaan_dateendField.getValue() !== null) && (add_pelaksanaan_dateendField.getValue() !== "")){add_end_date_field = add_pelaksanaan_dateendField.getValue();}
				if((add_valueField.getValue() !== null) && (add_valueField.getValue() !== "")){add_value_field = add_valueField.getValue();}
				
				//push data detail
				var adddet_id_field = [];
				var badet_id_field = [];
				var jobdet_id_field = [];
				var volume_field = [];
				var unit_id_field = [];
				var adddet_price_field = [];
				
				var dstore = adddetListEditorGrid.getStore();
				for(var i=0; i<dstore.getCount(); i++){
					if(dstore.getAt(i).data.jobdet_id!==undefined
							&& dstore.getAt(i).data.jobdet_id!==''
								&& dstore.getAt(i).data.jobdet_id!==0){
						adddet_id_field.push(dstore.getAt(i).data.adddet_id);
						badet_id_field.push(dstore.getAt(i).data.badet_id);
						jobdet_id_field.push(dstore.getAt(i).data.jobdet_id);
						volume_field.push(dstore.getAt(i).data.volume_add);
						unit_id_field.push(dstore.getAt(i).data.unit_id);
						adddet_price_field.push(dstore.getAt(i).data.adddet_price);
					}
				}
				var encoded_array_adddet_id = Ext.encode(adddet_id_field);
				var encoded_array_badet_id = Ext.encode(badet_id_field);
				var encoded_array_jobdet_id = Ext.encode(jobdet_id_field);
				var encoded_array_volume = Ext.encode(volume_field);
				var encoded_array_unit_id = Ext.encode(unit_id_field);
				var encoded_array_adddet_price = Ext.encode(adddet_price_field);
	
				Ext.Ajax.request({
					waitMsg: 'Please wait...',
					url: 'index.php?c=c_t_add&m=get_action',
					params: {
						add_id: add_id_field,
						add_kontrak: add_kontrak_field,
						add_type: add_type_field,
						add_seq: add_seq_field,
						add_req_date: add_req_date_field,
						add_req_no: add_req_no_field,
						add_acc_date: add_acc_date_field,
						add_acc_no: add_acc_no_field,
						add_date: add_date_field,
						add_no: add_no_field,
						add_begin_date: add_begin_date_field,
						add_end_date: add_end_date_field,
						add_value: add_value_field,
						
						//data detail jenis pekerjaan
						adddet_id: encoded_array_adddet_id,
						badet_id: encoded_array_badet_id,
						jobdet_id: encoded_array_jobdet_id,
						volume: encoded_array_volume,
						unit_id: encoded_array_unit_id,
						adddet_price: encoded_array_adddet_price,
						task: post2db
					},
					success: function(response){
						var result=eval(response.responseText);
						switch(result){
							case 1:
								Ext.MessageBox.alert(post2db+' OK',SUCCESS_SAVE);
								t_add_reset_form();
								t_add_DataStore.reload();
								break;
							default:
								Ext.MessageBox.show({
								   title: 'Warning',
								   msg: FAILED_SAVE,
								   buttons: Ext.MessageBox.OK,
								   animEl: 'save',
								   icon: Ext.MessageBox.WARNING
								});
								break;
						}
					},
					failure: function(response){
						Ext.MessageBox.show({
							   title: 'Error',
							   msg: FAILED_CONNECTION,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'database',
							   icon: Ext.MessageBox.ERROR
						});
					}
				});
	
			} else {
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_VALID_FORM,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
			}

		}
	}

  	function is_t_add_form_valid(){
		return (true);
	}

  	function t_add_set_form(){
		add_idField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('add_id'));
		add_branchField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('branch_name'));
		add_branchField.disable();
		add_projectField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('project_code'));
		add_projectField.disable();
		add_projectNameField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('project_name'));
		
		add_kontrakField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_no'));
		add_kontrakField.disable();
		add_typeField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('add_type'));
		add_seqField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('add_seq'));
		add_reqDateField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('add_reqdate'));
		add_reqNoField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('add_reqno'));
		add_accDateField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('add_accdate'));
		add_accNoField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('add_accno'));
		add_dateField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('add_date'));
		add_noField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('add_no'));

		add_pelaksanaan_datestartField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_begin'));
		add_kontrakend_dateField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_end'));

		var miliday = 24 * 60 * 60 * 1000;
		var addwaktu =  (t_add_ListEditorGrid.getSelectionModel().getSelected().get('add_end') - t_add_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_end')) / miliday;
		add_jangkawaktuField.setValue(addwaktu);
		add_pelaksanaan_datestartField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_begin'));
		add_pelaksanaan_dateendField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('add_end'));
		add_value_cfField.setValue(formatCurrency(t_add_ListEditorGrid.getSelectionModel().getSelected().get('add_value')));
		add_valueField.setValue(t_add_ListEditorGrid.getSelectionModel().getSelected().get('add_value'));

		kontrakDataStore.setBaseParam('branch_id', t_add_ListEditorGrid.getSelectionModel().getSelected().get('branch_id'));
		kontrakDataStore.setBaseParam('project_id', t_add_ListEditorGrid.getSelectionModel().getSelected().get('project_id'));
		kontrakDataStore.load({
			callback: function(opts, success, response){
				kontrakDataStore.filter([
				                         {
					                         property: 'kontrak_no',
					                         value: t_add_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_no'),
					                         anyMatch: false
				                         }
				         				]);
 				add_vendorDataField.updateDetail(kontrakDataStore.getAt(0).data);
 				add_initialDataField.updateDetail(kontrakDataStore.getAt(0).data);
			}
		});

		jobdetDataStore.load({
			callback: function(opts, success, response){
				unitDataStore.load({
					callback: function(opts, success, response){
						adddetDataStore.setBaseParam('kontrak_no', t_add_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_no'));
						adddetDataStore.setBaseParam('add_id', t_add_ListEditorGrid.getSelectionModel().getSelected().get('add_id'));
						adddetDataStore.load({
							callback: function(opts, success, response){
								var jmlawal = 0;
								var jmladd = 0;
								for(var i=0; i<adddetDataStore.getCount(); i++){
									jmlawal += (adddetDataStore.getAt(i).data.volume * adddetDataStore.getAt(i).data.kompdet_price);
									jmladd += (adddetDataStore.getAt(i).data.volume_add * adddetDataStore.getAt(i).data.adddet_price);
								}
								add_jmlawal_cfField.setValue(formatCurrency(jmlawal));
								set_valueminppn(jmlawal, 'nkawal');
								add_jmladd_cfField.setValue(formatCurrency(jmladd));
								set_valueminppn(jmladd, 'nkadd');
							}
						});
					}
				});
			}
		});

	}

  	function t_add_reset_form(){
  	  	add_idField.reset();
  	  	add_idField.setValue(null);
  	  	add_branchField.reset();
  	  	add_branchField.setValue(null);
  	  	add_projectField.reset();
	  	add_projectField.setValue(null);
	  	add_projectNameField.reset();
	  	add_projectNameField.setValue(null);
	  	add_kontrakField.reset();
	  	add_kontrakField.setValue(null);
	  	add_typeField.reset();
	  	add_typeField.setValue(null);
	  	add_seqField.reset();
	  	add_seqField.setValue(null);
	  	add_vendorDataField.resetDetail();
	  	add_initialDataField.resetDetail();
	  	add_reqDateField.reset();
	  	add_reqDateField.setValue(null);
	  	add_reqNoField.reset();
	  	add_reqNoField.setValue(null);
	  	add_accDateField.reset();
	  	add_accDateField.setValue(null);
	  	add_accNoField.reset();
	  	add_accNoField.setValue(null);
	  	add_dateField.reset();
	  	add_dateField.setValue(null);
	  	add_noField.reset();
	  	add_noField.setValue(null);
	  	add_jangkawaktuField.reset();
	  	add_jangkawaktuField.setValue(null);
	  	add_pelaksanaan_datestartField.reset();
	  	add_pelaksanaan_datestartField.setValue(null);
	  	add_pelaksanaan_dateendField.reset();
	  	add_pelaksanaan_dateendField.setValue(null);
	  	add_value_cfField.reset();
	  	add_value_cfField.setValue(null);
	  	add_valueField.reset();
	  	add_valueField.setValue(null);
	  	
	  	adddetDataStore.removeAll();
	  	add_jmlawal_cfField.reset();
	  	add_jmlawal_cfField.setValue(null);
	  	add_jmlnkawal_cfField.reset();
	  	add_jmlnkawal_cfField.setValue(null);
	  	add_jmladd_cfField.reset();
	  	add_jmladd_cfField.setValue(null);
	  	add_jmlnkadd_cfField.reset();
	  	add_jmlnkadd_cfField.setValue(null);
		add_projectField.enable();
		add_branchField.enable();
		add_kontrakField.enable();
	}

  	function t_add_refresh(){
		t_add_DataStore.baseParams = { task: 'LIST' };
		t_add_DataStore.reload({params: {start: 0, limit: pageS}});
	}

  	function display_form_window(){
		post2db='CREATE';
		msg='created';
		t_add_reset_form();
	}

  	function t_add_confirm_update(){
		/* only one record is selected here */
		if(t_add_ListEditorGrid.selModel.getCount() == 1) {
			post2db='UPDATE';
			msg='updated';
			t_add_set_form();
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_UPDATE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}

  	function t_add_confirm_delete(){
		// only one t_komp is selected here
		if(t_add_ListEditorGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_DELETE, t_add_delete);
		} else if(t_add_ListEditorGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_MULTI_DELETE, t_add_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_DELETE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	function t_add_delete(btn){
		if(btn=='yes'){

		var patt=new RegExp("D");
		if(patt.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{

			var selections = t_add_ListEditorGrid.selModel.getSelections();
			var prez = [];
			for(var i = 0; i< t_add_ListEditorGrid.selModel.getCount(); i++){
				prez.push(selections[i].json.add_id);
			}
			var encoded_array = Ext.encode(prez);
			Ext.Ajax.request({
				waitMsg: 'Please Wait',
				url: 'index.php?c=c_t_add&m=get_action',
				params: { task: "DELETE", ids:  encoded_array },
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
							t_add_DataStore.reload();
							break;
						default:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: FAILED_DELETE,
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
					});
				}
			});

			}

		}
	}
  	/* END FUNCTION */

	/* START CONTROL PERMISSION */
	/* END CONTROL PERMISSION */
	
});
</script>
<body style: 'background: url(assets/images/desktop.jpg)'>
<div>
	<div class="col">
		<div id="elwindow_t_add_save"></div>
		<div>&nbsp;</div>
		<div id="fp_t_add"></div>
    </div>
</div>
</body>
</html>